# -*- encoding: utf-8 -*-  
  
import urllib2  
from weixin.api.common import getAccToken
  
  
def crtMenu():
    access_token=getAccToken()
    print access_token
    posturl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token  
    print posturl
    menu = '''{
         "button":[
        {    
            "type":"view",
            "name":"天天惠",
            "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1ef1259eec8b148d&redirect_uri=http%3a%2f%2fwww.tiantianhw.cn%2fmshop%2findex.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
        },
        {    
                "type":"view",
                "name":"抢爆款",
                "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1ef1259eec8b148d&redirect_uri=http%3a%2f%2fwww.tiantianhw.cn%2fmshop%2findex.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
        },
        {
            "name":"常用",
            "sub_button":[
            {
                "name": "合作热线", 
                "type": "location_select", 
                "key": "rselfmenu_2_0",
                "sub_button": []
            },
             {
                "type":"view",
                "name":"在线客服",
                "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1ef1259eec8b148d&redirect_uri=http%3a%2f%2fkunshan.wuxizto.com%2ftownlist%2f&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
            },   
            {
                "type":"view",
                "name":"投诉建议",
                "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1ef1259eec8b148d&redirect_uri=http%3a%2f%2fkunshan.wuxizto.com%2fsuggest%2f&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
            },   
            {
                "type":"view",
                "name":"个人中心",
                "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1ef1259eec8b148d&redirect_uri=http%3a%2f%2fwww.tiantianhw.cn%2fmshop%2fhuiyuanshouye.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
            }]
        }]
     }'''  
      
    req=urllib2.urlopen(posturl, menu.encode('utf-8'))
    print req.read()  
crtMenu()
